<?php
/**
 * Created by PhpStorm.
 * User: liuwei
 * Date: 2017/5/15
 * Time: 下午2:37
 */

class Domain_User {

    private $model;

    public function __construct()
    {
        $this->model = new Model_User();
    }

    function getUserInfo($userId){
        return $this->model->getUserInfo($userId);
    }

    public function checkUsername($username)
    {
        $rowUser = $this->model->checkUsername($username);
        return ($rowUser)? true : false;
    }

    public function getUserByUsername($username)
    {
        return $this->model->checkUsername($username);
    }

    public function register($username,$password)
    {
        return $this->model->register($username,$password);
    }

    public function updateNickname($userId, $nickname) {
        $rs = array('code' => 0, 'msg' => '', 'info' => array());
        if ($this->model->checkNickname($nickname)){
            // 如果存在 昵称 返回
            $rs['code'] = -1;
            $rs['msg'] = '昵称已经存在，更新失败';
            return $rs;
        }
        if ($this->model->updateNickname($userId, $nickname)) {
            $rs['msg'] = '更新昵称成功';
        } else {
            $rs['code'] = -1;
            $rs['msg'] = '更新昵称失败';
        }
        return $rs;
    }

}
